var auditCountChart = echarts.init(document.getElementById('AuditCountChart'));
var applyRatiodataChart = echarts.init(document.getElementById('applyRatiodataChart'));
var inAuditCreditChart = echarts.init(document.getElementById('inAuditCreditChart'));
var chart4 = echarts.init(document.getElementById('chart4'));
var chart5 = echarts.init(document.getElementById('chart5'));

var auditData;
var applyRatiodata;
var inApplyCreditData;
var passRatioData;

function getTitleData() {
	$.ajax({
		cache : true,
		type : "POST",
		url : "report/getTitleDataList",
		async : false,
		error : function(request) {
			alert("Connection error");
		},
		success : function(data) {
			document.getElementById('commitSxCount').innerText=data.commitSxCount;
			document.getElementById('successSxCount').innerText=data.successSxCount;
			document.getElementById('avgAuditTime').innerText=data.avgAuditTime;
		}
	});
}

function getAuditCountData() {
	$.ajax({
		cache : true,
		type : "POST",
		url : "report/getAuditCountData",
		async : false,
		error : function(request) {
			alert("Connection error");
		},
		success : function(data) {
			auditData = data;
		}
	});
}

function getApplyRatioData() {
	$.ajax({
		cache : true,
		type : "POST",
		url : "report/getApplyRatioData",
		async : false,
		error : function(request) {
			alert("Connection error");
		},
		success : function(data) {
			applyRatiodata = data
		}
	});
}

function getInAuditCredit() {
	$.ajax({
		cache : true,
		type : "POST",
		url : "report/getInAuditCredit",
		async : false,
		error : function(request) {
			alert("Connection error");
		},
		success : function(data) {
			inApplyCreditData = data
		}
	});
}

function getPassRatio() {
	$.ajax({
		cache : true,
		type : "POST",
		url : "report/getPassRatio",
		async : false,
		error : function(request) {
			alert("Connection error");
		},
		success : function(data) {
			passRatioData = data
		}
	});
}


getTitleData();
getAuditCountData();
getApplyRatioData();
getInAuditCredit();
getPassRatio();

// 指定图表的配置项和数据
var AuditCountOption = {
	    title: {
	        text: '各级代理累计审核订单数',
	    },
	    tooltip: {
	        trigger: 'axis',
	        axisPointer: {
	            type: 'shadow'
	        }
	    },
	    grid: {
	        left: '3%',
	        right: '4%',
	        bottom: '3%',
	        containLabel: true
	    },
	    xAxis: {
	        type: 'value',
	        boundaryGap: [0, 0.01]
	    },
	    yAxis: {
	        type: 'category',
	        data: ['镇级代理','县级代理','总部']
	    },
	    series: [
	        {
	            type: 'bar',
	            data: auditData
	        }
	    ]
	};

var applyRatiodataOption = {
	    title : {
	        text: '各级代理授信申请订单占比'
	    },
	    tooltip : {
	        trigger: 'item',
	        formatter: "{a} <br/>{b} : {c} ({d}%)"
	    },
	    series : [
	        {
	            name: '访问来源',
	            type: 'pie',
	            radius : '55%',
	            center: ['50%', '60%'],
	            data:applyRatiodata,
	            itemStyle: {
	                emphasis: {
	                    shadowBlur: 10,
	                    shadowOffsetX: 0,
	                    shadowColor: 'rgba(0, 0, 0, 0.5)'
	                }
	            }
	        }
	    ]
	};

var inAuditCreditOption = {
	    title: {
	        text: '待审核授信申请订单数量',
	    },
	    tooltip: {
	        trigger: 'axis',
	        axisPointer: {
	            type: 'shadow'
	        }
	    },
	    grid: {
	        left: '3%',
	        right: '4%',
	        bottom: '3%',
	        containLabel: true
	    },
	    xAxis: {
	        type: 'value',
	        boundaryGap: [0, 0.01]
	    },
	    yAxis: {
	        type: 'category',
	        data: ['镇级代理','县级代理','总部']
	    },
	    series: [
	        {
	            type: 'bar',
	            data: inApplyCreditData
	        }
	    ]
	};

var option4 = {
	    color: ['#3398DB'],
	    title: {
	        text: '各级授信审批单均通过率',
	    },
	    tooltip : {
	        trigger: 'axis',
	        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
	            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
	        }
	    },
	    grid: {
	        left: '3%',
	        right: '4%',
	        bottom: '3%',
	        containLabel: true
	    },
	    xAxis : [
	        {
	            type : 'category',
	            data : ['总部', '县级代理', '镇级代理', '整体'],
	            axisTick: {
	                alignWithLabel: true
	            }
	        }
	    ],
	    yAxis : [
	        {
	            type : 'value'
	        }
	    ],
	    series : [
	        {
	            name:'比例(%)',
	            type:'bar',
	            barWidth: '60%',
	            data:passRatioData
	        }
	    ]
	};

var option5 = {
	    title: {
	        text: '各级代理审批效率趋势'
	    },
	    tooltip: {
	        trigger: 'axis'
	    },
	    legend: {
	        data:['总部','县级代理','镇级代理','村级代理']
	    },
	    grid: {
	        left: '3%',
	        right: '4%',
	        bottom: '3%',
	        containLabel: true
	    },
	    xAxis: {
	        type: 'category',
	        boundaryGap: false,
	        data: ['2017-05-01','2017-05-01','2017-05-01','2017-05-01','2017-05-01','2017-05-01','2017-05-01']
	    },
	    yAxis: {
	        type: 'value'
	    },
	    series: [
	        {
	            name:'总部',
	            type:'line',
	            stack: '总量',
	            data:[120, 132, 101, 134, 90, 230, 210]
	        },
	        {
	            name:'县级代理',
	            type:'line',
	            stack: '总量',
	            data:[220, 182, 191, 234, 290, 330, 310]
	        },
	        {
	            name:'镇级代理',
	            type:'line',
	            stack: '总量',
	            data:[150, 232, 201, 154, 190, 330, 410]
	        },
	        {
	            name:'村级代理',
	            type:'line',
	            stack: '总量',
	            data:[320, 332, 301, 334, 390, 330, 320]
	        }
	    ]
	};


// 使用刚指定的配置项和数据显示图表。
auditCountChart.setOption(AuditCountOption);
applyRatiodataChart.setOption(applyRatiodataOption);
inAuditCreditChart.setOption(inAuditCreditOption);
chart4.setOption(option4);

